package cn.com.bluemoon.daps.sync.feignclient;

import cn.com.bluemoon.daps.api.notice.RemoteNoticeHandlerService;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.notice.core.NoticeType;
import cn.com.bluemoon.daps.notice.template.ApplyPublishMessage;
import cn.com.bluemoon.daps.notice.template.DevSyncMessage;
import cn.com.bluemoon.daps.notice.template.ProSyncMessage;
import cn.com.bluemoon.daps.notice.template.base.BaseMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Jarod.Kong
 * @date 2021/6/15 16:05
 */
@Service
@Slf4j
public class DapNoticeModuleFacade {
    @Autowired
    private RemoteNoticeHandlerService noticeHandlerService;


    /**
     * 接收第三方的消息-开发同步
     *
     * @param type    消息类型，目前支持{@link NoticeType#EMAIL}
     * @param baseMsg 基础消息，目前自带有以下： （不满足可以自定义基于{@link BaseMessage}+freemarker模板到对应目录
     * @see DevSyncMessage
     * @see ProSyncMessage
     * @see ApplyPublishMessage
     */
    public boolean sendDevMsg(NoticeType type, DevSyncMessage baseMsg) {
        ResultBean<Boolean> res = noticeHandlerService.sendDevMsg(type, baseMsg);
        Boolean success = res.isOk();
        log.info("type=>{},发送情况：{}", type, success);
        return Boolean.TRUE.equals(success);
    }

    /**
     * 接收第三方的消息-生产同步
     *
     * @param type    消息类型，目前支持{@link NoticeType#EMAIL}
     * @param baseMsg 基础消息，目前自带有以下： （不满足可以自定义基于{@link BaseMessage}+freemarker模板到对应目录
     * @see DevSyncMessage
     * @see ProSyncMessage
     * @see ApplyPublishMessage
     * @return
     */
    public boolean sendProMsg(NoticeType type, ProSyncMessage baseMsg) {
        ResultBean<Boolean> res = noticeHandlerService.sendProMsg(type, baseMsg);
        Boolean success = res.getContent();
        log.info("type=>{},发送情况：{}", type, success);
        return Boolean.TRUE.equals(success);
    }
    /**
     * 接收第三方的消息-申请发布同步
     *
     * @param type    消息类型，目前支持{@link NoticeType#EMAIL}
     * @param baseMsg 基础消息，目前自带有以下： （不满足可以自定义基于{@link cn.com.bluemoon.daps.notice.template.base.BaseMessage}+freemarker模板到对应目录
     * @see DevSyncMessage
     * @see ProSyncMessage
     * @see ApplyPublishMessage
     */
    public boolean sendApplyMsg(NoticeType type, ApplyPublishMessage baseMsg) {
        ResultBean<Boolean> res = noticeHandlerService.sendApplyMsg(type, baseMsg);
        Boolean success = res.assetTrue();
        log.info("type=>{},发送情况：{}", type, success);
        return Boolean.TRUE.equals(success);
    }
}
